package com.lawyer.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.persistence.EntityManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.lawyer.entity.SelectConfig;
import com.lawyer.model.Message;
import com.lawyer.model.MessageConstant;
import com.lawyer.repository.SelectConfigRepository;
import com.lawyer.repository.UserRepository;

@RestController
@RequestMapping(value = "/selectConfig")
@Api(tags = "下拉选项配置")
@SuppressWarnings("all")
public class SelectConfigController {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private UserRepository userRepository;

	@Autowired
	private SelectConfigRepository selectConfigRepository;

	@Autowired
	private EntityManager entityManager;

	@ApiOperation(httpMethod = "GET", value = "根具code获取下拉列表", notes = "根具code获取下拉列表")
	@RequestMapping(value = "/queryByCode", method = RequestMethod.GET)
	public HttpEntity<?> queryByCode(String code) {
		Message msg = new Message();
		try {
			List<SelectConfig> data = selectConfigRepository.findByCodeOrderByOrderIndexAsc(code);

			msg.setData(data);
		} catch (Exception e) {
			msg.setCode(MessageConstant.FAILED_CODE);
			msg.setMessage(MessageConstant.FAILED_MSG);
		}

		return new ResponseEntity<>(msg, HttpStatus.OK);
	}

}
